{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:42:43.000976Z",
     "start_time": "2019-09-30T11:42:42.552743Z"
    }
   },
   "outputs": [],
   "source": [
    "from skimage import morphology\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:42:43.005319Z",
     "start_time": "2019-09-30T11:42:43.002548Z"
    }
   },
   "outputs": [],
   "source": [
    "a = np.array([[0, 0, 0, 1, 0],\n",
    "              [1, 1, 1, 0, 0],\n",
    "              [1, 1, 1, 0, 0],\n",
    "              [0, 0, 0, 1, 1]], bool)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:42:43.014611Z",
     "start_time": "2019-09-30T11:42:43.006784Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False, False, False, False, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [False, False, False,  True,  True]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = morphology.remove_small_objects(a, 2)\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:22:01.526951Z",
     "start_time": "2019-09-30T11:22:01.524392Z"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:42:43.018912Z",
     "start_time": "2019-09-30T11:42:43.015837Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False, False, False, False, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [False, False, False, False, False]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = morphology.remove_small_objects(a, 6, connectivity=1)\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:42:43.023238Z",
     "start_time": "2019-09-30T11:42:43.019844Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False, False, False,  True, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [False, False, False,  True,  True]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = morphology.remove_small_objects(a, 6, connectivity=2)\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:42:43.026611Z",
     "start_time": "2019-09-30T11:42:43.024084Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False, False, False, False, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [ True,  True,  True, False, False],\n",
       "       [False, False, False, False, False]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = morphology.remove_small_objects(a, 6, in_place=True)\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-30T11:20:45.468680Z",
     "start_time": "2019-09-30T11:20:45.460361Z"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
